<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>心灵笔触</title>
    <link rel="stylesheet" href="css/conmmon.css">
    <link rel="stylesheet" href="css/blog_list.css">
    <script src="js/jquery.min.js"></script>
    <script src="js/logout.js"></script>


    <style>
        .container-right table {
            font-weight: bold;
            font-size: 16.5px;
            margin: 15px auto;
        }

        .table11_7 {
            border-collapse: collapse;
            border-radius: 10px;
            overflow: hidden;
        }

        .table11_7 table {
            width: 100%;
            margin: 15px 0;
            border: 0;
        }

        .table11_7 th {
            background-color: #045d8d;
            color: #FFFFFF
        }

        .table11_7 tr {
            height: 50px;
            /* 设置行高为50像素 */
        }

        .table11_7,
        .table11_7 th,
        .table11_7 td {
            font-size: 0.95em;
            text-align: center;
            padding: 4px;
            border-collapse: collapse;
        }

        .table11_7 th,
        .table11_7 td {
            border-width: 1px 0 1px 0;
            border: 2px inset #ffffff;
            border: 1px solid rgba(128, 128, 128, 0.2);

        }

        .table11_7 tr {
            border: 1px solid #ffffff;
        }

        .table11_7 tr:nth-child(odd) {
            background-color: #ffffff;
        }

        .table11_7 tr:nth-child(even) {
            background-color: #ffffff;
        }

        .btn1-style {
            background-color: rgb(205, 58, 70);
            color: white;
            border: none;
            padding: 8px 12px;
            font-size: 14px;
            border-radius: 4px;
            cursor: pointer;
        }

        .btn2-style {
            background-color: rgb(68, 212, 145);
            color: white;
            border: none;
            padding: 8px 12px;
            font-size: 14px;
            border-radius: 4px;
            cursor: pointer;
        }
    </style>
</head>

<body>
    <!-- 导航栏 -->
    <div class="nav">
        <img src="img/logo3.jpg" alt="">
        <span class="title">管理员中心</span>
        <!-- 用来占据中间位置 -->
        <span class="spacer"></span>
        <a href="reader_list2.html">返回</a>
        <a href="admin_search.html">搜索</a>
        <!-- <a href="javascript:logout()">注销</a> -->
        <a href="javascript:logout()">退出</a>
    </div>
    <!-- 版心 -->
    <div class="container">

        <!-- 右侧内容详情 -->
        <div id="artListDiv" class="container-right" style="margin-left: 10%">
            <!-- <a href=""
                style="text-decoration: none; color: black;padding-left: 15px;padding-top: 15px;display: block;">书籍管理 >>
            </a>
            <table class=table11_7 width="790px">
                <tr>
                    <th>用户名</th>
                    <th>证明</th>
                    <th>当前进度</th>
                    <th>操作</th>
                </tr>
                <tr>
                    <td id="username">李白</td>
                    <td id="type">我是诗人</td>
                    <td id="state">申请中</td>
                    <td>
                        <button class="btn1-style" onclick="doPass()">通过</button>
                        &nbsp;
                        <button class="btn2-style" onclick="doReject()">拒绝</button>
                    </td>
                </tr>
                <tr>
                    <td id="username">三国演义</td>
                    <td id="type">施耐庵</td>
                    <td id="state">申请中</td>
                    <td>
                        <button class="btn1-style" onclick="doPass()">通过</button>
                        &nbsp;
                        <button class="btn2-style" onclick="doReject()">拒绝</button>
                    </td>
                </tr>
            </table> -->
        </div>
    </div>
    <script>
        //初始化方法
        function init() {
            jQuery.ajax({
                url: "/admin/adminwriter",
                type: "GET",
                data: {},
                success: function (res) {
                    if (res.code == 200) {
                        // 请求成功
                        var createHtml = "";
                        createHtml += '<a href="admin_list.html" style="text-decoration: none; color: black;padding-left: 15px;padding-top: 15px;display: inline-block;">用户管理 > </a>'
                        createHtml += '<a href="admin2_list.html" style="text-decoration: none; color: black;padding-left: 15px;padding-top: 15px;display: inline-block;">文章管理 > </a>'
                        var artList = res.data;
                        if (artList == null || artList.length == 0) {
                            // 没有用户
                            createHtml += "<h3 style='margin-left:20px;margin-top:20px;'>当前没有作者注册申请</h3>";
                        } else {
                            createHtml += '<table class=table11_7 width="790px">';
                            createHtml += '<tr>';
                            createHtml += '<th>用户名</th>';
                            createHtml += '<th>证明</th>';
                            createHtml += '<th>当前进度</th>';
                            createHtml += '<th>操作</th>';
                            createHtml += '</tr>';
                            for (var i = 0; i < artList.length; i++) {
                                var art = artList[i];
                                createHtml += '<tr>';
                                createHtml += '<td id="username">' + art.username + '</td>';
                                createHtml += '<td id="prove">' + art.prove + '</td>';
                                createHtml += '<td id="state">' + art.state + '</td>';
                                createHtml += '<td>';
                                createHtml += '<button class="btn1-style" onclick="doPass()">通过</button>';
                                createHtml += '&nbsp;';
                                createHtml += '<button class="btn2-style" onclick="doReject()">拒绝</button>';
                                createHtml += '</td>';
                                createHtml += '</tr>';

                            }
                            createHtml += '</table>';
                        }
                        jQuery("#artListDiv").html(createHtml);
                    } else if (res.code == -2) {
                        alert("请先登录！");
                        location.href = "login.html";
                    } else {
                        alert("抱歉，操作失败" + res.msg);
                        location.href = "login.html";
                    }
                }
            })
        }
        init();

        // 通过申请
        function doPass() {
            var row = $(event.target).closest("tr");  // 获取点击按钮所在的行
            var username = row.find("#username").text();
            var prove = row.find("#prove").text();
            jQuery.ajax({
                url: "admin/writerpass",
                type: "POST",
                data: {
                    "username": username,
                    "prove": prove
                },
                success: function (res) {
                    if (res.code == 200 && res.data == 1) {
                        alert("操作成功，已通过该注册申请。");
                        location.href = location.href;
                    } else {
                        alert("操作失败" + res.msg);
                    }
                }
            });
        }

        // 拒绝申请
        function doReject() {
            var row = $(event.target).closest("tr");  // 获取点击按钮所在的行
            var username = row.find("#username").text();
            var prove = row.find("#prove").text();
            jQuery.ajax({
                url: "admin/writerreject",
                type: "POST",
                data: {
                    "username": username,
                    "prove": prove

                },
                success: function (res) {
                    if (res.code == 200 && res.data == 1) {
                        alert("操作成功，已拒绝该注册申请。");
                        location.href = location.href;
                    } else {
                        alert("操作失败" + res.msg);
                    }
                }
            });
        }



    </script>
</body>

</html>